package com.example.wan1.adapter;

import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.wan1.R;
import com.example.wan1.model.CoinBean;
import com.example.wan1.utils.SPUtils;
import com.example.wan1.utils.ToolsUtils;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

/***
 * 创建时间：2020/7/28 21:00
 * 创建人：10850
 * 功能描述：
 */
public class CoinRankListAdapter extends BaseQuickAdapter<CoinBean, BaseViewHolder> {

    private String userInfo;
    private String userName;

    public CoinRankListAdapter(int layoutResId, @Nullable List<CoinBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CoinBean item) {
        int layoutPosition = helper.getLayoutPosition();
        userInfo = (String) SPUtils.get(mContext, "user_info", "");
        userName = userInfo.split("-")[0];
        if (!TextUtils.isEmpty(userName)) {
            if (userName.regionMatches(3, item.getUsername(), 3, userName.length() - 3)) {
                helper.setTextColor(R.id.tv_rank_des, ContextCompat.getColor(mContext, R.color.coin_text_color));
                helper.setTextColor(R.id.tv_rank_coin, ContextCompat.getColor(mContext, R.color.coin_text_color));
                helper.setBackgroundRes(R.id.tv_rank_coin, R.drawable.tag_rank_blue_background);
            } else {
                helper.setTextColor(R.id.tv_rank_des, ContextCompat.getColor(mContext, R.color.textColorPrimary));
                helper.setTextColor(R.id.tv_rank_coin, ContextCompat.getColor(mContext, R.color.textColorPrimary));
                helper.setBackgroundRes(R.id.tv_rank_coin, R.drawable.tag_rank_gray_background);
            }
        }
        helper.setText(R.id.tv_rank_des, (layoutPosition + 1) + ". " + item.getUsername() + " 积分：" + item.getCoinCount())
                .setText(R.id.tv_rank_coin, "lv " + ToolsUtils.getRank(item.getCoinCount()));
    }
}
